--- An internal qualified name.
module frege.compiler.types.QNames where 

import  frege.compiler.types.Packs

--- qualified name
data QName =
          TName { !pack :: Pack,  !base :: String }
        | VName { !pack :: Pack,  !base :: String }
        | MName { !tynm :: QName, !base :: String }
        | Local { !uid  :: Int,   !base :: String }
    where
        getpack (TName p _) = p
        getpack (VName p _) = p
        getpack (MName (TName p _) _) = p
        getpack (MName _ _) = Prelude.error "illegal MName"
        getpack (Local{}) = Pack.new ""

        --- tell if a 'QName' is from a certain package
        frompack q p = getpack q == p  


        key (TName _ s)  = "T+" ++ s
        key vmName       = vmName.base

        --- tell if this names a tuple constructor or type
        istuple s   = QName.base s ~ ´^\(,+\)$´
        --- change the base name 
        qual    (TName p  _)   = TName p
        qual    (VName p  _)   = VName p
        qual    (MName t  _)   = MName t
        qual    (Local {uid})  = Local uid
        --- tell if this is the name of a let or lambda bound item
        isLocal (Local{}) = true
        isLocal _         = false


derive Eq   QName


derive Ord  QName


derive Show QName


{-- (isTName x) ist das Wahre gdw. x unter den Begriff Typname fällt -}
isTName (TName _ _) = true
isTName _           = false


